<%--
  Created by IntelliJ IDEA.
  User: bxc
  Date: 2018/9/5 0005
  Time: 11:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>合同管理</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <style>
        td {
            width: 100px;
            height: 16px;
            line-height: 16px;
            text-align: center;
            vertical-align: middle;
        }
        #stoped{
            border-color: red;
            color: red;
            background: white;
        }
    </style>
</head>
<body>

<center>
    <h2>合同列表</h2><br/>
    <% String pri = request.getParameter("prid");
       int prid = Integer.parseInt(pri);
       request.setAttribute("prid1",prid);
    %>
    <a href="/rentsys/agreen/toAdd?prid=${prid1}" >
        <input type="button" value="添加合同" style="margin-left: -1000px;margin-bottom: 20px"></a><br/>
    <form action="" method="post">
        <table border="1" cellspacing="0">
            <tr style="background: gainsboro">
                <td>合同编号</td>
                <td>起始时间</td>
                <td>结束时间</td>
                <td>收款周期</td>
                <td>保证金</td>
                <td>免租期</td>
                <td>租赁面积</td>
                <td>租赁单价</td>
                <td>递增率</td>
                <td>状态</td>
                <td>操作</td>
            </tr>
            <c:forEach items="${agreens}" var="ag">
                <tr>
                    <td>${ag.id}</td>
                    <td><fmt:formatDate value="${ag.start_time}"/> </td>
                    <td><fmt:formatDate value="${ag.end_time}"/></td>
                    <td>${ag.pay_period}</td>
                    <td>￥${ag.prepay}</td>
                    <td>${ag.free_period}</td>
                    <td>${ag.rent_size}平米</td>
                    <td>￥${ag.price}</td>
                    <td>${ag.rate_increase}%</td>
                    <td>${ag.state}</td>
                    <td><input id="stoped" type="button" value="终止" onclick="stop(${ag.id})"/></td>
                </tr>
            </c:forEach>
        </table>
    </form>
</center>


<script>
    function stop(aid){
        $.ajax({
            url:"/rentsys/agreen/stop",
            type:"POST",
            data:{
                aid:aid
            },
            dataType: 'json',
            /*contentType:"application/json;charset=utf-8",*/
            success: function (result) {
                if(result.errorCode == 200){
                    alert(result.errorMsg)
                    window.location.href="/rentsys/agreen/getAll?prid=${prid1}";
                }else {
                    alert("合同信息更新失败！")
                }
            },
            error: function () {
                alert("请求失败！")
            }
        });

    }


</script>
</body>
</html>
